LL_COMP_Init and LL_COMP_DeInit APIs migration ¶
The LL initialization and de-initialization functions previously available in the
stm32tnxx_ll_comp.c
files
within HAL1 are no longer present in HAL2.
In HAL2, all LL C files (
stm32tnxx_ll_comp.c) have been removed, leaving only the LL header files (
stm32tnxx_ll_comp.h)
that contain static inline functions.
If users need to initialize or de-initialize COMP using the LL layer, they have two methods:
Utilize STM32CubeMX2 Code Generation: Rely on STM32CubeMX2 to generate code with the LL layer for COMP initialization and de-initialization.
- Replace manually the initialization and de-initialization functionsReplace the
LL_COMP_InitandLL_COMP_DeInitfunctions manually with equivalent sequences using the static inline functions provided in the
stm32tnxx_ll_comp.hfile, tailored to their specific configuration and requirements.
- Replace manually the initialization and de-initialization functionsReplace the
This approach ensures that the initialization and de-initialization sequences are precisely addressing the given use case based on the LL static inline functions provided in the
stm32tnxx_ll_comp.h
header file.
The sequences offer improved footprint optimization compared to the previous LL initialization functions found in
stm32tnxx_ll_comp.c.
Related concept: Remove stm32tnxx_ll_ppp.c files
Method 1: Utilize STM32CubeMX2 Code Generation ¶
LL COMP configuration panel ¶
Create a new project with the STM32CubeMX2, then start the initialization and the main configuration.
LL COMP main features configuration ¶
Configure the COMP main features
LL COMP advanced features configuration ¶
Configure the advanced features of the COMP if needed
LL COMP GPIO configuration ¶
Configure the GPIOs needed by the COMP
LL COMP EXTI configuration ¶
Configure the EXTI as needed.
LL COMP NVIC configuration ¶
Configure the NVIC if the application requires the COMP interrupts
Generated COMP initialization sequence ¶
The COMP initialization and de-initialization sequences are generated in the
mx_comp1_init
and
mx_comp1_deinit
functions in
mx_comp1.c
file under
$YOUR_PROJECT_NAME$/$YOUR_PROJECT_NAME$_SW/generated/STM32Cube_CodeGen.
|
Topic |
Code Snippet HAL1 |
Code Snippet HAL2 |
|---|---|---|
|
Init and config sequence function |
static void MX_COMP1_Init(void)
{
LL_COMP_InitTypeDef COMP_InitStruct = {0};
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
/* Peripheral clock enable */
LL_APB1_GRP2_EnableClock(LL_APB3_GRP1_PERIPH_COMP);
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB);
/**COMP1 GPIO Configuration
PB2 ------> COMP1_INP
*/
GPIO_InitStruct.Pin = LL_GPIO_PIN_2;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* COMP1 interrupt Init */
NVIC_SetPriority(COMP_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0, 0));
NVIC_EnableIRQ(COMP_IRQn);
COMP_InitStruct.InputPlus = LL_COMP_INPUT_PLUS_IO2;
COMP_InitStruct.InputMinus = LL_COMP_INPUT_MINUS_1_4VREFINT;
COMP_InitStruct.InputHysteresis = LL_COMP_HYSTERESIS_NONE;
COMP_InitStruct.OutputPolarity = LL_COMP_OUTPUTPOL_NONINVERTED;
COMP_InitStruct.OutputBlankingSource = LL_COMP_BLANKINGSRC_NONE;
LL_COMP_Init(COMP1, &COMP_InitStruct);
LL_COMP_SetPowerMode(COMP1, LL_COMP_POWERMODE_HIGHSPEED);
/* Wait loop initialization and execution */
/* Note: Variable divided by 2 to compensate partially CPU processing cycles */
__IO uint32_t wait_loop_index = 0;
wait_loop_index = (LL_COMP_DELAY_VOLTAGE_SCALER_STAB_US * (SystemCoreClock / (1000000 * 2)));
while(wait_loop_index != 0)
{
wait_loop_index--;
}
LL_COMP_SetCommonWindowMode(__LL_COMP_COMMON_INSTANCE(COMP1), LL_COMP_WINDOWMODE_DISABLE);
LL_COMP_SetCommonWindowOutput(__LL_COMP_COMMON_INSTANCE(COMP1), LL_COMP_WINDOWOUTPUT_EACH_COMP);
LL_EXTI_ClearFallingFlag_0_31(LL_EXTI_LINE_17);
LL_EXTI_ClearRisingFlag_0_31(LL_EXTI_LINE_17);
LL_EXTI_EnableRisingTrig_0_31(LL_EXTI_LINE_17);
LL_EXTI_DisableFallingTrig_0_31(LL_EXTI_LINE_17);
LL_EXTI_DisableEvent_0_31(LL_EXTI_LINE_17);
LL_EXTI_EnableIT_0_31(LL_EXTI_LINE_17);
}
|
COMP_TypeDef *mx_comp1_init(void)
{
LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_COMP12);
LL_COMP_SetPowerMode(COMP1, LL_COMP_POWER_MODE_HIGH_SPEED);
LL_COMP_ConfigInputs(COMP1, LL_COMP_INPUT_MINUS_1_4VREFINT, LL_COMP_INPUT_PLUS_IO2);
/* LL_COMP_SetInputHysteresis(COMP1, LL_COMP_HYSTERESIS_NONE); */
/* LL_COMP_SetOutputPolarity(COMP1, LL_COMP_OUTPUTPOL_NONINVERTED); */
LL_COMP_SetOutputBlankingSource(COMP1, LL_COMP_BLANKINGSRC_TIM1_OC5);
/* GPIO Clocks activation */
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB);
/**
COMP1 GPIO Configuration
[GPIO Pin] ------> [Signal Name]
PB0 ------> COMP1_INP2
**/
/* Activate the Pull-up, Pull-down resistor, or No pull for the current IO */
LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_0, LL_GPIO_PULL_NO);
/* Configure IO direction mode (Input, Output, Alternate or Analog) */
LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_0, LL_GPIO_MODE_ANALOG);
LL_EXTI_EnableRisingTrig_32_63(LL_EXTI_LINE_34);
return COMP1;
}
|
|
Deinit sequence function |
void MX_COMP1_DeInit(void)
{
LL_COMP_DeInit(COMP1);
/* ### GPIO deinitialization of COMP1: COMP1 ########################### */
LL_APB1_GRP2_DisableClock(LL_APB1_GRP2_PERIPH_COMP12);
LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_COMP12);
LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_COMP12);
}
|
void mx_comp1_deinit(void)
{
LL_COMP_Disable(COMP1);
LL_APB1_GRP2_DisableClock(LL_APB1_GRP2_PERIPH_COMP12);
LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_COMP12);
LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_COMP12);
/* ### GPIO deinitialization of COMP1: COMP1_INP2 ########################### */
/* Configure IO in Analog Mode */
LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_0, LL_GPIO_MODE_ANALOG);
/* Configure the default Alternate Function in current IO */
LL_GPIO_SetAFPin_0_7(GPIOB, LL_GPIO_PIN_0, LL_GPIO_AF_0);
/* Configure the default value for IO Speed */
LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_0, LL_GPIO_SPEED_FREQ_LOW);
/* Configure the default value IO Output Type */
LL_GPIO_SetPinOutputType(GPIOB, LL_GPIO_PIN_0, LL_GPIO_OUTPUT_PUSHPULL);
/* Deactivate the Pull-up and Pull-down resistor for the current IO */
LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_0, LL_GPIO_PULL_NO);
/* Reset the IO output state */
LL_GPIO_WriteOutputPin(GPIOB, LL_GPIO_PIN_0, LL_GPIO_PIN_RESET);
}
|
Method 2: Replace manually the initialization and de-initialization functions ¶
LL_COMP_Init() API migration ¶
According to the use-case, implement the precise sequence call based on the LL static inline functions provided in
the
stm32tnxx_ll_comp.h
header file.
|
HAL1 |
HAL2 |
|---|---|
LL_COMP_InitTypeDef comp_initStruct;
/* use the default values initialization */
LL_COMP_StructInit(comp_initStruct);
/*Or*/
/* Set COMP_InitStruct fields to default values */
COMP_InitStruct->PowerMode = LL_COMP_POWERMODE_ULTRALOWPOWER;
COMP_InitStruct->InputPlus = LL_COMP_INPUT_PLUS_IO1;
COMP_InitStruct->InputMinus = LL_COMP_INPUT_MINUS_VREFINT;
COMP_InitStruct->InputHysteresis = LL_COMP_HYSTERESIS_NONE;
COMP_InitStruct->OutputPolarity = LL_COMP_OUTPUTPOL_NONINVERTED;
COMP_InitStruct->OutputBlankingSource = LL_COMP_BLANKINGSRC_NONE;
LL_COMP_Init(COMP1, comp_initStruct);
|
/**/
LL_COMP_SetPowerMode(COMP1, LL_COMP_POWERMODE_ULTRALOWPOWER);
LL_COMP_SetInputPlus(COMP1, LL_COMP_INPUT_PLUS_IO1);
LL_COMP_SetInputMinus(COMP1, LL_COMP_INPUT_MINUS_VREFINT);
LL_COMP_SetInputHysteresis(COMP1, LL_COMP_HYSTERESIS_NONE);
LL_COMP_SetOutputPolarity(COMP1, LL_COMP_OUTPUTPOL_NONINVERTED);
LL_COMP_SetOutputBlankingSource(COMP1, LL_COMP_BLANKINGSRC_NONE);
|
LL_COMP_DeInit() API migration ¶
According to the used COMP instance, Implement the precise calls to
LL_COMP_WRITE_REG().
Example: The application is using COMP1
|
HAL1 |
HAL2 |
|---|---|
LL_COMP_DeInit(COMP1);
|
LL_COMP_WRITE_REG(COMP1, CSR, 0x00000000UL);
|